import requests
import json

headers = {
    'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) '
                  'Chrome/70.0.3538.102 Safari/537.36',
}


def get_fan_list(SESSDATA,pid):
    cookies = {
        'SESSDATA': SESSDATA,
    }
    print('>> 正在从bilibili获取最近1000个粉丝...')
    fan_list = []
    for pn in range(1, 21):
        url = 'http://api.bilibili.com/x/relation/followers?vmid=%s&pn=%s' %(pid,pn) 
        res = requests.get(url, headers, cookies=cookies)
        py_obj = json.loads(res.text)
        data_list = py_obj.get('data')['list']
        fan_list.extend(data_list)
    return fan_list


def get_fan_fan(mid):
    url = 'https://api.bilibili.com/x/relation/stat?vmid=%s&jsonp=jsonp' % mid
    res = requests.get(url)
    py_obj = json.loads(res.text)
    return py_obj.get('data')['follower']